//
//  CModel.swift
//  CooperSwift
//
//  Created by CooperSwift on 2021/04/27 12:06:20.
//  Copyright © 2021 CooperSwift. All rights reserved.
//

import WCDBSwift

class CModel: TableCodable {

    var id: Int!
    var d: Int?
    var e: String?

    enum CodingKeys: String, CodingTableKey {
        typealias Root = CModel

        case id
        case d
        case e

        static let objectRelationalMapping = TableBinding(CodingKeys.self)

        //Column constraints for primary key, unique, not null, default value and so on. It is optional.
        static var columnConstraintBindings: [CodingKeys: ColumnConstraintBinding]? {
            return [
                .id: ColumnConstraintBinding(isPrimary: true, isAutoIncrement: true),
//                .variable2: ColumnConstraintBinding(isUnique: true)
            ]
        }

        //Index bindings. It is optional.
        //static var indexBindings: [IndexBinding.Subfix: IndexBinding]? {
        //    return [
        //        "_index": IndexBinding(indexesBy: CodingKeys.variable2)
        //    ]
        //}

        //Table constraints for multi-primary, multi-unique and so on. It is optional.
        //static var tableConstraintBindings: [TableConstraintBinding.Name: TableConstraintBinding]? {
        //    return [
        //        "MultiPrimaryConstraint": MultiPrimaryBinding(indexesBy: variable2.asIndex(orderBy: .descending), variable3.primaryKeyPart2)
        //    ]
        //}

        //Virtual table binding for FTS and so on. It is optional.
        //static var virtualTableBinding: VirtualTableBinding? {
        //    return VirtualTableBinding(with: .fts3, and: ModuleArgument(with: .WCDB))
        //}
    }

    //Properties below are needed only the primary key is auto-incremental
    var isAutoIncrement: Bool = true
    var lastInsertedRowID: Int64 = 0
}

    
